/**
 * Created by 长春驿枫 on 2016/9/18.
 */


;!(function(){
	
	var __functionForForm=function(layer,WebUploader){
    window.layer=layer;
    Ladder.layer=layer;
    var includes = [
        Ladder.BasicURL + "/third/layer/skin/layer.css",
        Ladder.BasicURL + "/third/layer/skin/layer.ext.css",
        Ladder.BasicURL + "/third/webuploader/webuploader.css",
        Ladder.BasicURL + "/css/ladder-formtemplate.css"
    ];
    Ladder.include(includes);
    // Ladder.include(GetRequireUrl() + "../third/laydate/laydate.js");
    Ladder.WebUploader=WebUploader;
    Ladder.NS("Form");
    Ladder.Form={
        /**
         * 创建一个表单输入元素
         * @param config {Json}配置信息
         * @param value {String/Number} 现行值
         * @returns {dom}
         */
        createForm:function(config,value){
            if(config.hasOwnProperty("settings")&&/%7B/.test(config["settings"]))config.settings=decodeURIComponent(config.settings);
            if(config.hasOwnProperty("datasource")&&/%7B/.test(config["datasource"]))config.datasource=decodeURIComponent(config.datasource);
            if(Ladder.form){
                var $input = Ladder.form.Components.createEl(config.wname);
                if(value)$input.val(value);
                if(Ladder[config.wname]){
                    new Ladder[config.wname]($input, config.settings?config.settings:config);
                }else{
                    for(var pname in config){
                        Ladder.form.handleEl($input,pname,config[pname]);
                    };
                    Ladder.form.parseEl($input,true);
                }
                if(config.yui&&Ladder[config.yui]){
                    var settings=config.settings||config["yui-config"]||config;
                    new Ladder[config.yui]($input, settings);

                }
                return $input;
            }else {
                alert("对不起，您引用的组件库不全，建议引用[YF_form.js]");
            }
        },
        /***
         * 构造表单
         * 与createForm不同，此方法是建立整个表单
         * @param render {selector} 渲染的元素
         * @param data {Array} 各元素配置数据
         * @param format {String} 格式化
         * @param callback {String} 回调函数
         * @returns {boolean}
         */
        buildForm:function(render,config,callback){
            if(!render||!config)return false;
            render=$(render);
            var settings={
                tableName:"",
                fields:null,
                group:null,
                mode:"table",//table list
            }
            data = Ladder.toJSON(config);
            switch (Ladder.getType(config)){
                case "Array":
                    settings.fields=config;
                    break;
                case "Object":
                    $.extend(settings,config);
                    break;
                default:
                    return;
            }
            var NoFindFields={};
            //创建分组签
            function createGroup(name){
                if(!name)name="default";
                if(render.find(".yui-tform-container[data-group='"+name+"']").length>0)
                    return render.find(".yui-tform-container[data-group='"+name+"'] .yui-tform-tabletemplate");
                var $container=$("<div data-group='"+name+"' class='yui-tform-container'></div>").appendTo(render);
                var $formhead=$("<div class='yui-tform-head'></div>").appendTo($container);
                var $title=$("<div class='fl title'>"+name+"</div>").appendTo($formhead);
                if(name=="default" && !settings.group)$formhead.hide();
                if(name=="default" && settings.group)$title.html(settings.group);
                $('<div class="fr control" ><i class="iconfont up"></i></div>').appendTo($formhead).click(function(){
                    var el =  $(this).find(".iconfont");
                    if(el.hasClass("up")){
                        el.removeClass("up").addClass("down");
                        $container.find(".yui-tform-tabletemplate").fadeOut().hide();
                    }else{
                        el.removeClass("down").addClass("up");
                        $container.find(".yui-tform-tabletemplate").fadeIn();
                    }
                });
                var $tform=undefined;
                switch (settings.mode){
                    case "table":
                        $tform= $("<table class='yui-tform-tabletemplate'></table>").appendTo($container);
                        break;
                    case "flow":
                    case "list":
                        $tform= $("<ul class='yui-tform-tabletemplate'></ul>").appendTo($container);
                        break;

                }
                return $tform;
            }
            //处理联动
            function hanlderLinkagebyitem(item,$input) {
                if(item.linkage){
                    var linktype = Ladder.getType(item.linkage);
                    var _sett={
                        fieldName:"",
                        attrname:"data-intent",
                        valueprop:"value",
                        event:"change",
                        dom:$input
                    }
                    switch (linktype){
                        case "String":
                            var _sets = item.linkage.split("|");
                            _sett.fieldName=_sets[0];
                            if(_sets.length>1)_sett.attrname=_sets[1];
                            if(_sets.length>2)_sett.event=_sets[2];
                            break;
                        case "Object":
                            $.extend(_sett,item.linkage);
                            break;
                    }

                    var $link = render.find("[data-fieldname='"+_sett.fieldName+"']");
                    if($link.length<1)NoFindFields[_sett.fieldName]=_sett;
                    else {
                        $link.on(_sett.event,function(){
                            _sett.dom.empty();
                            _sett.dom.attr(_sett.attrname,(_sett.valueprop=="value"?$(this).val():$(this).attr(_sett.valueprop)));
                            for(var pname in item){
                                Ladder.form.handleEl(_sett.dom,pname,item[pname]);
                            };
                        });
                        var es = $link.attr("data-linlageEvent");
                        if(es){
                            if(es.indexOf(_sett.event)<0)$link.attr("data-linkageEvent",es+" "+_sett.event);
                        }else{
                            $link.attr("data-linlageEvent",_sett.event);
                        }
                    }
                }
                if(NoFindFields.hasOwnProperty(item.fieldname)){
                    var _set=NoFindFields[item.fieldname];
                    $input.on(_set.event,function(){
                        _set.dom.empty();
                        _set.dom.attr(_set.attrname,(_set.valueprop=="value"?$(this).val():$(this).attr(_set.valueprop)));
                        for(var pname in item){
                            Ladder.form.handleEl(_set.dom,pname,item[pname]);
                        };
                    });
                    var es = $input.attr("data-linkageEvent");
                    if(es){
                        if(es.indexOf(_set.event)<0)$input.attr("data-linkageEvent",es+" "+_set.event);
                    }else{
                        $input.attr("data-linlageEvent",_set.event);
                    }
                }
            }
            switch (settings.mode){
                case "table":
                {
                    settings.fields.forEach(function(item, index) {
                        var $tform=createGroup(item.groupname);
                        var $tr = $("<tr></tr>").addClass("js-formarea").attr("data-tableName",settings.tableName);
                        if(item.index != undefined && item.index != null){
                            var $lis=$tform.find(".js-formarea");
                            if(item.index*1>$lis.length-1){
                                $tform.append($tr);
                            }else{
                                $($lis[item.index*1]).before($tr);
                            }
                        }else{
                            $tform.append($tr);
                        }
                        if(item.dom){
                            var $td=$("<td colspan='3'></td>");
                            var $dom=$(item.dom);
                            if($dom.length>0) {
                                $td.appendTo($tr).append($dom.show());
                                return;
                            }
                        }
                        if(item.isshow===false||item.editable===false){
                            return;
                        }
                        var $th = $("<th width='120px' class='js-title'>" + item.title + "</th>").appendTo($tr);
                        var $w = Ladder.Form.createForm(item, item.dvalue);
                        var $td = $("<td class='td-form js-input'></td>").appendTo($tr).append($w);
                        if(/require/.test(item.valid)){
                            $td.append("<div class='sign'>*</div>")
                        }
                        if(item.span==2)$td.attr("colspan", 2);
                        if (item.wname == "textfield") {
                            $td.attr("colspan", 2);
                            $w.css({"width":"95%",height:70});
                            return;
                        }
                        if (!item.descr)item.descr = "";
                        var id = (item.fieldname ? item.fieldname : "hint") + Ladder.uuid(20);
                        var $td = $("<td class='js-hint' id='" + id + "'>" + item.descr + "</td>").appendTo($tr);
                        $w.attr("data-validselector", "#" + id);
                        if (item.gen && /(id)|(autonum)/.test(item.gen)) $tr.hide();
                        if(item.editable=="0")$tr.hide();
                        if(item.callback){
                            if(item.callback($tr,item,$tform)===false)return;
                        }
                        hanlderLinkagebyitem(item,$w);
                    });
                }
                    break;
                case "flow":
                case "list":
                {
                    settings.fields.forEach(function(item, index) {
                        if(item.isshow===false||item.editable===false){
                            return;
                        }
                        var $tform=createGroup(item.groupname);
                        var $block = $("<li></li>").attr("data-tableName",settings.tableName).addClass("js-formarea");
                            // .appendTo($tform);
                        if(item.index != undefined && item.index != null){
                            var $lis=$tform.find(".js-formarea");
                            if(item.index*1>$lis.length-1){
                                $tform.append($block);
                            }else{
                                $($lis[item.index*1]).before($block);

                            }
                        }else{
                            $tform.append($block);
                        }
                        if(item.dom){
                            var $div=$("<div></div>");
                            var $dom=$(item.dom);
                            if($dom.length>0) {
                                $div.appendTo($block).append($dom.show());
                                return;
                            }
                        }
                        $("<div class='block-caption js-title'>" + item.title + "</div>").appendTo($block);
                        var $w = Ladder.Form.createForm(item, item.dvalue);
                        if(settings.tableName)$w.attr("data-tableName",settings.tableName);
                        var $td = $("<div class='block-form js-input'></div>").appendTo($block).append($w);
                        if(/require/.test(item.valid)){
                            $td.append("<div class='sign'>*</div>")
                        }
                        if (item.wname == "textfield") {
                            $block.before("<br>");
                            $block.after("<br>");
                            $w.css({
                                width:490,height:60
                            });
                        }
                        if(item.span==2){
                            $w.css({
                                width:490
                            });
                        }
                        if (item.gen && /(id)|(autonum)/.test(item.gen)) $block.hide();
                        if(item.editable=="0")$block.hide();
                        if(item.callback){
                            if(item.callback($td,item,$tform)===false)return;
                        }
                        hanlderLinkagebyitem(item,$w);
                    });
                }
                    break;
            }
            if(callback)callback();
            return true;
        },
        setFieldConfig: function (fieldName, obj) {
            var tar = $("[data-fieldname=" + fieldName + "]");
            var $tr = $("<tr id='new'></tr>")
            var $th = $("<th width='120px'>" + obj.title + "</th>").appendTo($tr);
            var $w = Ladder.Form.createForm(obj, obj.dvalue);
            var $td = $("<td width='250px' align='left'></td>").appendTo($tr).append($w);

            var id = (obj.fieldname ? obj.fieldname : "hint") + Ladder.uuid(20);
            if (!obj.descr) obj.descr = "";
            var $td2 = $("<td class='js-hint' id='" + id + "'>" + obj.descr + "</td>").appendTo($tr);
            $w.attr("data-validselector", "#" + id);
            if (obj.gen && /(id)|(autonum)/.test(obj.gen)) {
                $tr.hide();
            }
            //tar.parents("tr").empty().append($tr);
            tar.parents("tr").before($tr);
            tar.parents("tr").remove();
            //$(document.body).append($tr);
            //tar.parent().append($tr);
        },
        /**
         * 设置表单元素的属性
         * @param parent 父级元素
         * @param prop {Function/String} 属性名称,如果是function类型则回调方法
         * @param value 属性值
         * @returns {boolean}
         */
        setFormAttr:function(parent,prop,value){
            if(!prop)return false;
            var els=$(parent).find("."+Ladder.form.Components.fetchMark);
            if(els.length<1)return false;
            els.each(function(){
                var $this=$(this);
                if(Ladder.getType(prop)=="Function"){
                    prop($this);
                    return;
                }
                if(value===null){
                    $this.removeAttr(prop);return;
                }
                if(Ladder.getType(value)==="Boolean"){
                    $this.prop(prop,value);return;
                }
                $this.attr(prop,value);return;

            });
            return true;
        },

        /**
         * 设置表单元素的值
         * 1）可以设置归一元素，比如checkbox radio
         * 2) 可以是上传图片框的图片
         * 3）下拉框进行重复值判断
         * @param parent 父级元素
         * @param value 值对象
         * @param prop 元素的属性值和值对象的匹配,比如data-bind="id",value.id,
         * @param filter  过滤选择器
         * @returns {boolean}
         */
        setFormValue: function (parent,value,prop,filter,callback) {
            if (prop == undefined) prop = "id";
            var $inputs = $(parent).find("." + Ladder.form.Components.fetchMark + "["+prop+"]");
            if ($inputs.length < 1) return false;
            if (filter) {
                $inputs=$inputs.not(filter);
                if ($inputs.length < 1) return false;
            }
            var radiobox=new Object();
            $inputs.each(function () {
                var $this=$(this);
                var wname=$this.data("wname")||$this.attr("type")||$this[0].tagName.toLowerCase();
                var re=new RegExp(Ladder.form.Components.joinRegEx,"gi");
                var key=$this.attr(prop);
                if(!re.test(wname)){
                    if(value){
                        if(value.hasOwnProperty(key)){
                            var formValue=value[key];
                            var _datatype=$this.data("type")||$this.data("datatype");
                            if(/date/.test(_datatype)){
                                //var vssss=value[key];
                                if(_datatype=="date"&&formValue.length>0){
                                    formValue=Ladder.dateFormat(formValue,"yyyy-MM-dd",0);
                                }
                                if(_datatype=="datetime"){
                                    if(/00:00:00\.0$/.test(formValue)||/0:00:00$/.test(formValue)){
                                        formValue=Ladder.dateFormat(formValue,"yyyy-MM-dd");
                                    }else{
                                        if(formValue.length>0)formValue=Ladder.dateFormat(formValue,"yyyy-MM-dd hh:mm:ss");
                                    }
                                }
                                if(callback){
                                    var ret=callback($this,key,value[key],value);
                                    if(ret===false)return;
                                    if(ret)formValue=ret;
                                }
                                Ladder.form.handleEl($this,"value",formValue);
                            }else{
                                Ladder.form.handleEl($this,"value",formValue);
                                //if this widget is combox
                                if (/(combox)|(select)/.test(wname)) {
                                    //if (value[key]&&!Ladder.form.containValue($this, value[key])) {
                                    if (value[key] && $this.find("option[value='" + formValue + "']").length<1) {
                                        var genel = $("<option value='" + formValue + "'>" + formValue + "</option>");
                                        $this.prepend(genel);
                                        genel.prop("selected", "selected");
                                    }else{
                                        Ladder.form.handleEl($this,"value",formValue);
                                    }
                                    if(callback){
                                        var ret=callback($this,key,value[key],value);
                                        if(ret===false)return;
                                        if(ret)formValue=ret;
                                    }
                                }else{
                                    if (wname == "imageupload") {
                                        var randomval = $this.attr("data-imgrandom");
                                        if(formValue){
                                            if(/^~/.test(formValue))formValue=formValue.replace(/^~/,Ladder.ServerUrl);
                                            $("#imageview" + randomval).html($("<img>").attr("src", formValue).css({
                                                width:"100%",height:"100%"
                                            }));
                                        }
                                    }
                                    if(callback){
                                        var ret=callback($this,key,value[key],value);
                                        if(ret===false)return;
                                        if(ret)formValue=ret;
                                    }
                                }
                            }

                        }else{
                            var formValue="";
                            if(callback){
                                var ret=callback($this,key,value[key],value);
                                if(ret===false)return;
                                if(ret)formValue=ret;
                            }
                            Ladder.form.handleEl($this,"value",formValue);
                        }
                    }else{
                        if(callback){
                            var ret=callback($this,key,value[key],value);
                            if(ret===false)return;
                            if(ret) Ladder.form.handleEl($this,"value",ret);
                            else Ladder.form.handleEl($this,"value","");
                        }
                    }
                }else{
                    //单选项的赋值
                    if(wname=="radio"){
                        if(!value){//值为空
                            if(!radiobox.hasOwnProperty(key))$this.prop("checked","checked");
                        }else{
                            if(value.hasOwnProperty(key) && $this.val()==value[key]){
                                $this.prop("checked","checked");
                            }
                        }
                    }
                    if(wname=="checkbox"){
                        if(!value)$this.prop("checked",false);
                        else{
                            if(value.hasOwnProperty(key) && (","+value[key]).indexOf(","+$this.val())>-1){
                                $this.prop("checked",true);
                            }else{
                                $this.prop("checked",false);
                            }
                        }
                    }
                    if(callback)callback($this,key,value[key],value);
                }
                var _event=$this.attr("data-linlageEvent");
                if(_event){
                    var es=_event.split(" ");
                    for(var i=0,len=es.length;i<len;i++){
                        if(es[i])$this.trigger(es[i]);
                    }
                }
            });
            return true;
        },
        /**
         * 获取表单组件上的值
         * @param {selector} parent 父组件
         * @param {string} prop 取字段名的对应属性
         * @param {string} format 文本格式化，当为"data",进行空排除
         * @param {string} valType 取值的对应属性,其属性值为空时，自动转化成value属性的值
         * @param {string} dv 默认值的属性值
         * @returns {object}
         */
        fetchFormValue: function (parent, prop, format, valType, dv) {

            var $parent = $(parent);
            if ($parent.find("[data-valid],[data-wname]").length > 0 && !Ladder.form.validForm($parent,true)) {
                return null;
            }
            //从参数中获取回调函数
            var callback=null;
            for (var i = 0; i < arguments.length; ++i){
                if(Ladder.getType(arguments[i])=="Function"){
                    callback=arguments[i];
                    switch (i){
                        case 2:
                            format=false;
                            break;
                        case 3:
                            valType=null;
                            break;
                        case 4:
                            dv=null;
                            break;
                        // default:
                        //     return {};
                    }
                }
            }
            if(prop==undefined)prop="id";
            if($(parent).find("."+Ladder.form.Components.fetchMark+"["+prop+"]").length<1)return false;
            var bean=new Object();
            var joinField=new Object();
            $(parent).find("."+Ladder.form.Components.fetchMark+"["+prop+"]").each(function(){
                var me=$(this);
                var wname = me.data("wname");
                if (!wname) wname = me.attr("type");
                //bean中此属性被预加载，则不再取值
                if(bean.hasOwnProperty(me.attr(prop)))
                    return;
                var re=new RegExp(Ladder.form.Components.joinRegEx,"gi");
                if(re.test(wname)){
                    //如果没有data-main 标识挂接在第一个元素上，如多个data-main只在第一个有效
                    var name=me.attr("name");
                    if(joinField.hasOwnProperty(name)){
                        var tx=joinField[name];
                        var joinname=me.attr("data-main");
                        if(joinname*1==1&&tx.allowchange){
                            tx.id=me.attr(prop);
                        }
                        if (me.prop("checked")) {
                            if (tx.value) tx.value += "," + (valType ? me.attr(valType) || me.val() : me.val());
                            else tx.value = valType ? me.attr(valType) || me.val() : me.val();
                        }
                    }else{
                        var joinname = me.attr("data-main");
                        joinField[name] = {
                            allowchange: joinname * 1 == 1 ? false : true,
                            id: me.attr(prop),
                            value: me.prop("checked") ? (valType ? me.attr(valType) || me.val() : me.val()) : undefined
                        };
                    }
                }else{
                    var id = me.attr(prop);
                    var value;
                    if(/(text)|(html)/.test(valType)){
                        value = eval("me."+valType+"()");
                    }else{
                        value = valType ? (me.attr(valType) || me.val()) : me.val();
                    }
                    if((value==undefined||value.length<1)&&dv&&Ladder.getType(dv)=="String")value=me.attr(dv)||"";
                    bean[id] = value;
                }
                if(format==="data"&&Ladder.form.Valids.isNull(value)){
                    delete bean[id];
                }
                if(callback&&callback(me,id,value,bean)===false)delete bean[id];
            });
            for(var ttt in joinField){
                var tbean=joinField[ttt];
                bean[tbean.id] = tbean.value;
                if (format === "data" && Ladder.form.Valids.isNull(tbean.value)) {
                    delete bean[tbean.id];
                }
                if (callback && callback(null, tbean.id, tbean.value, bean) === false) delete bean[id];
            }
            if(format==undefined ||format===true)
                bean=JSON.stringify(bean);
            return bean;
        },
        getElementValue:function(el,prop, format, valType, dv){
            el = $(el);
            var len=el.length
            if(len<1)return null;
            var copyels = el.clone();
            var $div=$("<div></div>").append(copyels);
            var data=this.fetchFormValue($div,prop,format,valType,dv);
            if(len==1){
                if(data&&prop)return data[el.attr(prop)];
                else return null;
            }
            return data
        },
        /**
         * 验证表单
         * @param {selector} parent 父级标签
         * @param {boolean} single 遇到一个错误就返回
         * @returns {boolean}
         */
        validForm:function(parent,single) {
            return Ladder.form.vaildForm(parent, single);
        },
        /**
         * 验证元素
         * @param {} el 元素，可以是选择器
         * @returns {boolean} 通过返回真
         */
        check: function (el) {
            el = $(el);
            if (el.length > 1) {
                var result = true;
                for (var i = 0, len = el.length; i < len; i++) {
                    result = Ladder.form.Valids.check(el[i]);
                    if(result===false)break;
                }
                return result;
            }
            return Ladder.form.Valids.check(el);
        },
        /**
         *  下拉组件数据组装
         * @param el,元素选择器
         * @param data 填充数据,可以是AjaxJson，如果是文本，只进行添加或者替换
         * @param baseval，空白值和配置键值，
         * 1）默认为空，下拉框表示留有空白
         * 2）false：不留空白
         * 3）true:下拉框表示留有空白
         * 4) 文本值，通过':'分割，前者是值后者是标题
         * 5) 对象型，配置option的value和title的键名，比如｛value:"id",title:"name"}
         * @param isClear,是否清除原值，默认清空
         * @param isUpdateItem,
         * 1)是否按照原值显示,选项追加多项的话，进行原值显示,
         * 2)true为更新原值，变成新设置的值，false为不更新
         * 3)如果不传参数，当数据为一条或者数值时，自动进行值更新
         */
        setSelectValue: function (el, data, baseval, isClear, isUpdateItem) {
            var $el = $(el);
            if ($el.length > 1) {
                $el.each(function() {
                    Ladder.Form.setSelectValue(this, data, baseval, isClear, isUpdateItem);
                });
                return;
            }
            var key_value = "value", key_title = "title",key_callback=null;

            if($el.length<1)return;
            var type=Ladder.getType(data);
            if(type==="Object"){
                //test type is ajaxjson object
                if(data==undefined||data==null){
                    setbaseval();
                    return;
                }
                if(data.hasOwnProperty("statusCode")&&data.statusCode==200){
                    if(!data["data"]){//如果数据为空
                        setbaseval();
                        return;
                    }else{
                        Ladder.form.setSelectValue(el,data["data"],baseval,isClear,isUpdateItem);
                        return;
                    }
                }else{
                    appendData(data);
                }
            }
            if(type==="Array"){
                pusharray(data);
            }
            if(type==="Number"){
                appendData({title:data,value:data});
                el.val(data);
                return;
                //if(isUpdateItem==undefined)isUpdateItem=true;
            }
            //如果设置数据是文本,进行文本分割，如果分割数组为1，置选项
            if (type === "String") {
                var dataarray = new Array();
                var items = data.split("|");
                var itemvalue=data;
                for (var i = 0; i < items.length; i++) {
                    var item = items[i].split(":", 2);
                    itemvalue=item[item.length - 1];
                    dataarray.push({value: item[item.length - 1],title: item[0]});
                }
                pusharray(dataarray);
                if(items.length==1){
                    $el.val(itemvalue);
                    return;
                    //if(isUpdateItem==undefined)isUpdateItem=true;
                }
            }
            //如果置值
            if($el.data("cmval")||$el.data("value")||$el.attr("value")){
                $el.val($el.data("cmval")||$el.data("value")||$el.attr("value"));
                return;
            }
            var _val = $el.data("cmval")||$el.val();//默认值
            if(_val!=undefined&&(!isUpdateItem))$el.val(_val);
            function pusharray(arraydata){
                setbaseval();
                for(var i=0;i<arraydata.length;i++){
                    if(Ladder.getType(arraydata[i])!="Object"){
                        appendData({value:arraydata[i]});
                    }else{
                        appendData(arraydata[i]);
                    }

                }
            }
            function setbaseval(){
                if (isClear == undefined || isClear) {
                    var $defbase = $el.find("[data-default]");
                    if ($defbase.length < 1) $el.empty();
                    else $defbase.siblings().remove();
                }

                if(!(baseval===false)){
                    if (!baseval) baseval = "";
                    var basetype = Ladder.getType(baseval);
                    if (basetype === "String") {
                        var temp = baseval.split(":");
                        if ($el.find("option[value='" + temp[0] + "']").length < 1)
                            $el.append("<option value='" + temp[0] + "'>" + temp[temp.length - 1] + "</option>");
                    }
                    else if (basetype === "Object") {
                        if (baseval.value) key_value = baseval.value;
                        if (baseval.title) key_title = baseval.title;
                        if (baseval.callback) key_callback = baseval.callback;
                        //判断配置项里是否有base
                        if(baseval.base==undefined){
                            if ($el.find("option[value='']").length < 1) $el.append("<option value=''></option>");
                        }
                        //如果是文本，进行值填充
                        else if(Ladder.getType(baseval.base)=="String"){
                            var temp = baseval.base.split(":");
                            if ($el.find("option[value='" + temp[0] + "']").length < 1)
                                $el.append("<option value='" + temp[0] + "'>" + temp[temp.length - 1] + "</option>");
                        }
                        //如果是false,删除空白项
                        else if(baseval.base===false){
                            $el.find("option[value='']").remove();
                        }
                    }
                    else {
                        if ($el.find("option[value='']").length < 1)$el.append("<option value=''></option>");
                    }
                }
            }
            //内部函数
            function appendData (obj){
                if (!obj) return;
                if(obj[key_value]==undefined && obj[key_title]==undefined&&!key_callback)return;//when both is null ，return
                if(obj[key_value]!=undefined || obj[key_title]!=undefined){
                    if (obj[key_value] == undefined) obj[key_value] = obj[key_title];
                    if (obj[key_title] == undefined) obj[key_title] = obj[key_value];
                    //if (!Ladder.form.containValue($el, obj[key_value])) {
                    var $opt=null;
                    if ($el.find("option[value='" + obj[key_value] + "']").length < 1) {
                        $opt = $("<option value='" + obj[key_value] + "'>" + obj[key_title] + "</option>").data("data", obj);
                        $el.append($opt);
                    }else{
                        $opt=$el.find("option [value='" + obj[key_value] + "']").html(obj[key_title]).data("data", obj);//更新旧值
                    }
                }
                if(key_callback){
                    key_callback($opt,obj,$el);
                }
            }
        }
    };
    Ladder.NS("FormDialog");
    /**
     * 表单编辑弹框
     * @param option 初始化参数
     * @param el 渲染的元素，如果空，渲染到body
     * @constructor
     */
    Ladder.FormDialog=function(option,el){
        /**
         * 父级容器
         * @type {null}
         */
        this.parent=null;
        /**
         * 查询条件
         * @type {null}
         */
        this.condition=null;
        /**
         * 字段模型
         * @type {null}
         */
        this.FieldModel=null;
        /**
         * 字段扩展配置
         * @type {{}}
         */
        this.extColumn={};
        /**
         * 实体数据对象
         * @type {null}
         */
        this.bean=null;
        /**
         * 操作选项
         * @type {number}
         */
        this.option=0;
        /**
         * 上下文数据
         * @type {null}
         */
        this.context=null;
        /***
         * 保存前数据
         * @type {null}
         */
        this.raw=null;//原数据
        /***
         * 对话框的ID
         * @type {null}
         */
        this.dialogid=null;
        /***
         * 数据模版列表
         * @type {null}
         */
        this.tables=null;
        /**
         * 是否完整
         * @type {boolean}
         */
        this.complete=false;
        /***
         * 通知机制
         * @type {{}}
         */
        this.notifys={};
        /***
         * 基本设置
         * @type {{parent: null, getUrl: string, saveUrl: string, tableName: string, width: number, height: string, css: string, build: boolean, pname: string, mode: string, onRender: null, onRequest: null, onSetValue: null, onGetValue: null, onError: null, onResult: null}}
         */
        this.settings = {
            /**
             * 获取数据的路径
             */
            parent:null,
            getUrl:  "default",
            saveUrl: "default",
            tableName: "",
            columns:"",
            width:800,
            height:"auto",
            css: "",
            build:true,
            pname: "fieldname",
            mode:"table",
            formFormat:false,
            onRender: null,
            onRequest: null,
            onSetValue:null,
            onGetValue:null,
            onError:null,
            onResult:null,
            keep:false
        };
        if(Ladder.getType(option)=="String")option=Ladder.toJSON(option);
        switch (Ladder.getType(option)){
            case "String":
                this.settings.tableName=option;
                break;
            case "Number":
                this.settings.option=option;
                break;
            case "Object":
                $.extend(this.settings,option);
                break;
        }
        el=el||this.settings.parent;
        this.parent=(el?$(el):$("<div style='display: none'></div>").appendTo(document.body));
        if(!this.settings.height)this.settings.height="auto";
        if(this.settings.build)this.init();
    };
    Ladder.FormDialog.prototype={
        init:function(callback){
            var me=this;
            me.complete=false;
            if(me.FieldModel){
                me.tables=[];
                for(var table in me.FieldModel){
                    var model=me.FieldModel[table];
                    me.tables.push(table);
                    var formconfig={
                        tableName:table,
                        mode:me.settings.mode,
                        group:me.settings.group,
                        fields:model
                    };
                    Ladder.Form.buildForm(me.parent,formconfig,me.settings.onRender);
                    if (me.settings.css){
                        setTimeout(function(){
                            Ladder.Form.setFormAttr(me.parent, result, function (el) {
                                el.addClass(me.settings.css);
                            });
                        });
                    }
                    if(callback)callback();
                }

                return;
            }
            if(me.settings.tableName){
                me.FieldModel={};
                me.tables=me.settings.tableName.split(",");
                webajax(URLS.DataModel, { tableName:me.settings.tableName,pname:"editable",columns:me.settings.columns}, function (result) {
                    if (result.statusCode == 200 && result.data) {
                        for(var table in result.data){
                            var model=result.data[table];
                            var groupname=undefined;
                            if(me.settings.group){
                                switch (Ladder.getType(me.settings.group)){
                                    case "String":
                                        groupname=me.settings.group;
                                        break;
                                    case "Object":
                                        groupname=me.settings.group[tableName];
                                        break;
                                }
                            }
                            for(var i= 0,len=result.data[table].length;i<len;i++){
                                var item=model[i];
                                if(me.extColumn.hasOwnProperty(item.fieldname)){
                                    $.extend(item,me.extColumn[item.fieldname]);
                                }
                                if(me.extColumn.hasOwnProperty(table+"."+item.fieldname)){
                                    $.extend(item,me.extColumn[table+"."+item.fieldname]);
                                }
                                if(groupname && !item.groupname){
                                    item.groupname=groupname;
                                }
                            }
                            me.FieldModel[table]=model;
                            var formconfig={
                                tableName:table,
                                mode:me.settings.mode,
                                group:me.settings.group,
                                fields:model
                            };
                            Ladder.Form.buildForm(me.parent,formconfig,me.settings.onRender);
                            if (me.settings.css){
                                setTimeout(function(){
                                    Ladder.Form.setFormAttr(me.parent, result, function (el) {
                                        el.addClass(me.settings.css);
                                    });
                                });
                            }
                            if(callback)callback();
                        }
                        me.complete=true;
                    }else {
                        if (me.settings.onError) me.settings.onError(result.statusCode, result.message);
                        else layer.msg("网络数据服务出现错误，请重试");
                    }
                    //通知监控事件
                    if(me.notifys["init"]){
                        me.notifys["init"].forEach(function(item){
                            if(item)item(me.tables,result);
                        });
                    }
                });
                // function renderForms(tableName){
                //
                // }
                // me.tables.forEach(function(item){
                //     renderForms(item);
                // });
            }
        },
        setTableName:function(tableName) {
            if (!tableName) return;
            var me=this;
            me.parent.empty();
            webajax(URLS.DataModel, { tableName: tableName,pname:"editable",columns:me.settings.columns }, function (result) {
                Ladder.Form.buildForm(me.parent, result.data, me.settings.onRender);
                if (me.settings.css)
                    Ladder.Form.setFormAttr(me.parent, result, function (el) {
                        el.addClass(me.settings.css);
                    });
            });
        },
        open:function(data,option,callback,config){
            var me=this;
            me.option = option;
            me.setValue(data);
            me._showDialog(callback,config);
        },
        setFormValue:function(name,value,pname){
            var me=this;
            var table_name=name.split(".");
            var $el=undefined;
            if(table_name.length>1){
               $el =  me.parent.find(".js-formarea[data-tableName='"+table_name[0]+"'] [data-fieldname='"+table_name[1]+"']");
            }else{
                $el =  me.parent.find(".js-formarea [data-fieldname='"+table_name[0]+"']");
            }
            if(pname){
                $el.attr(pname,value);
            }else{
                $el.val(value);
            }
        },
        setValue:function(data){
            var me=this;
            var _data=Ladder.toJSON(data);
            if(Ladder.getType(data)=="Object"&&data.hasOwnProperty("statusCode")&&data.hasOwnProperty("data")){
                _data=data.data;
            }
            me.raw=_data;
            function __setFormValue(tableName,data){
                var def={};
                var converts={__length:0};
                if(me.FieldModel[tableName]){
                    me.FieldModel[tableName].forEach(function(item){
                        var dv=item.dvalue||item.value||item.defaultVaule;
                        var name=item[me.settings.pname];
                        if(me.extColumn[name]&&dv==undefined)dv=me.extColumn[name].dvalue||me.extColumn[name].value||me.extColumn[name].defaultVaule;
                        if(dv!=undefined)def[name]=dv;
                        if(item.convert){
                            converts.__length+=1;
                            if(/%7B/.test(item.convert))item.convert=decodeURIComponent(item.convert);
                            converts[name]=Ladder.toJSON(item.convert);
                        }
                    });
                }
                $.extend(def,data);

                var $tableform=me.parent;
                var $forms=me.parent.find(".js-formarea[data-tableName='"+tableName+"']");
                if($forms.length>0)$tableform=$forms;
                //如果含有转换字段
                if(converts.__length>0){
                    Ladder.Form.setFormValue($tableform, def, "data-"+me.settings.pname,null,function(el,id,value,bean){
                        if(converts.hasOwnProperty(id)){
                            $(el).attr("data-value",value);
                            $(el).val("");
                            var configs=converts[id];
                            if(value){
                                configs.condition={};
                                configs.condition[configs["fieldname"]]=value;
                                webajax(URLS.GetData,configs,function(result){
                                    if(result.statusCode==200)$(el).val(Ladder.toString(result.data,",","",configs["columns"]));
                                });
                                return;
                            }
                        }
                        if(me.settings.onSetValue)me.settings.onSetValue(el,id,value,bean)
                    });
                }else{
                    Ladder.Form.setFormValue($tableform, def, "data-"+me.settings.pname,null,me.settings.onSetValue);
                }
            }

            if(me.tables.length==1)__setFormValue(me.tables[0],_data);
            else {
                me.tables.forEach(function(item) {
                    //如果以tableName为键对象包裹
                    if (_data.hasOwnProperty(item) && Ladder.getType(_data[item]) == "Object") {
                        __setFormValue(item, _data[item]);
                    } else {
                        __setFormValue(item, _data);
                    }
                });
            }

        },
        getValue:function(name){
            var me=this;
            if(me.tables.length<2){
                var data = Ladder.Form.fetchFormValue(me.parent, "data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                if(!data)return null;
                if(name){

                    return data[name.replace(me.settings.tableName+".")];
                }
                return data;
            }
            else{
                var table=undefined;
                var field=undefined;
                if(name){
                   var _tf =  name.split(".");
                   if(_tf.length<2)field=name;
                   else {
                       table=_tf[0];
                       field=_tf[1];
                   }
                }
                if(!field){
                    var ret={};
                    me.tables.forEach(function(item){
                        var data = Ladder.Form.fetchFormValue(me.parent.find(".js-formarea[data-tableName='"+item+"']"), "data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                        if(!data)ret[item]=null;
                        else ret[item]=data;
                    })
                    return ret;
                }
                else{
                    if(table){
                        var data = Ladder.Form.fetchFormValue(me.parent.find(".js-formarea[data-tableName='"+table+"']"), "data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                        return data[field];
                    }else {
                        var fel=me.parent.find(".js-formarea[data-"+me.settings.pname+"='"+field+"']");
                        return Ladder.Form.getElementValue(fel,"data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                    }
                }
            }

        },
        save:function(callback){
            var me=this;
            if(Ladder.getType(callback)=="Number"){
                me.option=callback*1;
                callback=arguments[arguments.length-1];
            }
            if (me.option != 1 && me.option != 2) {
                me.bean = Ladder.Form.fetchFormValue(me.parent, "data-" + me.settings.pname, false, "data-value", "data-dvalue", me.settings.onGetValue);
                if (callback && Ladder.getType(callback)=="Function") callback(me.bean);
                return;
            }

            var action = "新增";
            if (me.option == 2) {
                action = "修改";
            }
            if(me.tables.length<1)return;
            if(me.option!=1 && !me.condition && me.settings.saveUrl){
                layer.msg("无法进行保存操作[缺少更新条件]");
                return;
            }
            if(me.tables.length==1){
                me.bean = Ladder.Form.fetchFormValue(me.parent, "data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                if (!me.bean) {
                    return;
                }
                if (me.settings.onRequest) {
                    var ret = me.settings.onRequest(me.bean, me.option,me.raw);
                    if (ret === false)return;
                }
                if(!me.settings.saveUrl&&!me.settings.onRequest){
                    callback(me.bean);
                    // layer.close(me.dialogid);
                    return;
                }
                var saveUrl=me.settings.saveUrl;
                if(me.settings.saveUrl=="default")saveUrl=URLS.SaveBean;
                webajax(saveUrl,
                    {
                        condition:(me.option!=1?me.condition:""),
                        tableName: me.settings.tableName,
                        bean:me.bean,
                        option: me.option
                    }, function(result) {
                        if(me.settings.onResult&&me.settings.onResult(result)===false){
                            return;
                        }
                        if (result.statusCode == 200) {
                            layer.msg(action+"保存成功");
                            if(callback)callback(result.data);
                        } else {
                            layer.msg(action + "保存失败[" + result.message + "]", { icon: 2 });
                        }
                        if(me.settings.keep&&me.option==1)return;
                        if(me.dialogid)layer.close(me.dialogid);
                 });
            }else{
                var savebeans={};
                 me.bean={};
                 for(var i= 0;i<me.tables.length;i++){
                     var item=me.tables[i];
                     me.bean[item]=Ladder.Form.fetchFormValue(me.parent.find(".js-formarea[data-tableName='"+item+"']"), "data-"+me.settings.pname,false,"data-value","data-dvalue",me.settings.onGetValue);
                     if(!me.bean[item])return;
                     savebeans[item]={
                         condition:(me.option!=1?me.condition[item]:""),
                         tableName:item,
                         bean:me.bean[item],
                         option:me.option
                     }
                 }
                if (!me.bean) {
                    return;
                }
                if (me.settings.onRequest) {
                    var ret = me.settings.onRequest(me.bean, me.option,me.raw);
                    if (ret === false)return;
                }
                if(!me.option){
                    if(callback)callback(me.bean)
                    return;
                }
                var saveUrl=me.settings.saveUrl;
                if(me.settings.saveUrl=="default")saveUrl=URLS.SaveBeans;

                if (me.settings.onRequest) {
                    var ret = me.settings.onRequest(me.bean, me.option,me.raw);
                    if (ret === false)return;
                }
                webajax(saveUrl,{settings:savebeans}, function(result) {
                        if (result.statusCode == 200) {
                            layer.msg(action+"保存成功");
                            if(callback)callback(result.data);
                        } else {
                            layer.msg(action + "保存失败[" + result.message + "]", { icon: 2 });
                        }
                        if(me.settings.keep&&me.option==1)return;
                        if(me.dialogid)layer.close(me.dialogid);
                 });
            }



        },
        add:function(callback){
            var me=this;
            if (!this.parent.html() || !this.settings.tableName) {
                layer.msg("对不起，表单未被初始化");
                return;
            }
            me.option = 1;
            me.setValue({});
            me._showDialog(callback);
        },
        /**
         * 析出更新表单
         * @param condition 获取数据条件
         * @param callback 回调事件
         * @param context 上下文数据对象
         */
        update:function(condition,callback,context){
            var me = this;
            if (!this.parent.html() || !this.settings.tableName) {
                layer.msg("对不起，表单未被初始化");
                return;
            }
            me.context=context;
            if(!condition){
                layer.msg("对不起,未指定更新条件");
                return ;
            }
            me.option = 2;
            me.condition = condition;
            if(me.tables.length<1)return;
            if(me.tables.length==1){
                webajax((me.settings.getUrl=="default"?URLS.GetBean:me.settings.getUrl), { tableName: me.settings.tableName, condition: me.condition }, function(result) {
                    if (result.statusCode == 200 && result.data) {
                        me.setValue(result.data);
                        me._showDialog(callback);
                    } else {
                        layer.msg("获取修改数据失败", { icon: 2 });
                    }
                });
            }
            if(me.tables.length>1){
                var querys={};
                for (var i= 0,len=me.tables.length;i<len;i++){
                    var item=me.tables[i];
                    if(!condition[item]){
                        layer.msg("对不起,未指定更新条件");
                        return;
                    }
                    querys[item]={
                        tableName:item,
                        condition:condition[item],
                        option:10
                    }
                }
                webajax((me.settings.getUrl=="default"?URLS.Querys:me.settings.getUrl), {settings:querys }, function(result) {
                    if (result.statusCode == 200 && result.data) {
                        var ret={};
                        var count=0;
                        for (var i= 0,len=me.tables.length;i<len;i++){
                            var item=me.tables[i];
                            if(result.data[item].statusCode==200)ret[item]=result.data[item].data;
                            else{
                                count++;
                            }
                        }
                        if(count==me.tables.length){
                            layer.msg("对不起,获取数据失败");
                            return;
                        }
                        me.setValue(ret);
                        me._showDialog(callback);
                    } else {
                        layer.msg("获取修改数据失败", { icon: 2 });
                    }
                });






            }


        },
        delete:function(condition,callback) {
            var me=this;
            //if(me.tables.length>1){
            //    layer.msg("多对象更新保存暂不支持");
            //}
            if(Ladder.getType(condition)=="Function"){
                callback=condition;
                condition=null;
            }
            if(!condition)condition=me.condition;
            if(!condition){
                layer.msg("未有删除条件");
                return;
            }
            if(me.tables.length==1){
                layer.confirm('请您确认是否删除', {
                    btn: ['确认删除', '取消返回'], //按钮
                    shade: false //不显示遮罩
                }, function () {
                    webajax(me.settings.saveUrl=="default"?URLS.SaveBean:me.settings.saveUrl, {tableName:me.settings.tableName,condition:condition,option:-1}, function (json) {
                        if (json.statusCode == 200) {
                            layer.msg('数据删除成功！', { icon: 1 });
                            if(callback)callback();
                        }else
                            layer.msg('数据删除失败！', { icon:2});
                    });
                });
            }else{
                var deletes={};
                for(var i= 0,len=me.tables.length;i<len;i++){
                    var item=me.tables[i];
                    if(!condition[item]){
                        layer.msg("对不起,未指定删除条件");
                        return;
                    }
                    deletes[item]={
                        tableName:item,
                        option:-1,
                        condition:condition[item]
                    };
                    layer.confirm('请您确认是否删除', {
                        btn: ['确认删除', '取消返回'], //按钮
                        shade: false //不显示遮罩
                    }, function () {
                        webajax((me.settings.saveUrl=="default"? URLS.SaveBeans:me.settings.saveUrl), {settings:deletes}, function (json) {
                            if (json.statusCode == 200) {
                                layer.msg('数据删除成功！', { icon: 1 });
                                if(callback)callback();
                            }else
                                layer.msg('数据删除失败！', { icon:2});
                        });
                    });


                }
            }

        },
        setFieldConfig: function (name, config) {
            //Ladder.Form.setFieldConfig(field, obj);
            var me=this;
            var names = name.split(/,|\|/);
            names.forEach(function(field){
                var conf={};
                switch(Ladder.getType(config)){
                    case "String":
                        conf["title"]=config;
                        break;
                    case "Function":
                        conf["callback"]=config;
                        break;
                    case "Object":
                        conf=config;
                        break;
                    case "Boolean":
                        conf["isshow"]=config;
                        break;
                }
                if(me.extColumn.hasOwnProperty(field)){
                    $.extend(me.extColumn[field],conf);
                }else{
                    me.extColumn[field]=conf;
                }
            });
        },
        /**
         * 设置上下文数据
         * @param data 数据
         */
        setContext:function(data){
            this.context=data;
        },
        /**
         *获取上下文数据
         * @param name 属性名,如果为空，则返回整个数据对象
         * @returns {object} 数据
         */
        getContext: function (name) {
            if(name&&this.context){
               return this.context[name];
            }
            return this.context;
        },
        getRaw:function(name){
            if(name){
                if(this.raw)return this.raw[name];
                return null;
            }
          return this.raw;
        },
        _showDialog: function (callback, config) {

            var me = this;
            var height = me.settings.height.replace(/px/,"");
            var wh = $(window).height();
            if (wh < height) height = wh;
            me.dialogid=layer.open($.extend({
                type:1,
                title:(me.option == 2?"修改":"新增")+"操作",
                content:this.parent,
                area: [me.settings.width, height],
                btn:["保存","取消"],
                yes: function () {
                    me.save(callback);
                }
            },config));
        },
        getView:function() {
            return this.parent;
        },
        getInput: function (fieldname,tableName) {
            if(tableName){
               return this.parent.find(".js-formarea[data-tableName='"+tableName+"'] [data-"+this.settings.pname+"="+fieldname+"']");
            }
           return this.parent.find("[data-fieldname='" + fieldname + "']");
        },
        close:function(){
            if(this.dialogid)layer.close(this.dialogid);
        },
        addField:function(index,config){
            var me=this;
            var type = Ladder.getType(index);
            if(me.columnModel==null){
                me.columnModel=[config];
            }
            var $hideform=$("<div></div>");
            switch (type){
                case "String":
                    if(me.columnModel==null){
                        me.columnModel=[config];
                    }
                    else{
                        var fns= index.split(":");
                        var el = me.getInput(fns[0]);
                        if(el.length<1)return false;
                        var $next = el.parents(".js-formarea");
                        var settings={
                            mode:me.settings.mode,
                            fields:[config]
                        }
                        Ladder.Form.buildForm($hideform,settings);
                        if(fns.length<2 || fns[1] != "before"){
                            $next.after( $hideform.find(".js-formarea"));
                        }else{
                            $next.before( $hideform.find(".js-formarea"));
                        }

                    }
                    break;
                case "Number":
                   var $tr = me.getView().find(".js-formarea:eq("+index+")");
                    var settings={
                        mode:me.settings.mode,
                        fields:[config]
                    }
                    Ladder.Form.buildForm($hideform,settings);
                    $tr.after( $hideform.find(".js-formarea"));
                    break;
                case "Object":
                    var $tr = me.getView().find(".js-formarea:last");
                    Ladder.Form.buildForm($hideform,index);
                    $tr.after( $hideform.find(".js-formarea"));
                    break;
            }
        },
        addNotify:function(type,fun){
            var me=this;
            if(!me.notifys[type])me.notifys[type]=[];
            me.notifys[type].push(fun);
        }
    }
    Ladder.NS("FormFrame");
    Ladder.FormFrame=function(option){
        this.settings={
            url:"",
            method:"post",
        };
        if(Ladder.getType(option)==="String")this.settings.url=option;
        if(Ladder.getType(option)==="Object")$.extend(this.settings,option);
        var doc= $("<iframe style='display: none'></iframe>").appendTo(document.body)[0].contentDocument;
        doc.open();
        doc.write('<form method="'+this.settings.method+'" action="'+this.settings.url+'" id="form"></form>');
        doc.close();
        this.form=$("#form",doc);
    }
    Ladder.FormFrame.prototype={
        clear:function(){
            this.form.empty();
        },
        setForm:function(name,value){
            var $input=$("<input type='hidden'>").attr("name",name).val(Ladder.getType(value)=="Object"?JSON.stringify(value):value);
            this.form.append($input)
        },
        setBean:function(bean){
            var me=this;
            bean=Ladder.toJSON(bean);
            switch (Ladder.getType(bean)){
                case "Object":
                    for(var p in bean){
                        var $input=$("<input type='hidden'>").attr("name",p).val(Ladder.getType(bean[p])=="Object"?JSON.stringify(bean[p]):bean[p]);
                        me.form.append($input);
                    }
            }
        },
        submit:function(){
            this.form.submit();
        }
    }
    Ladder.NS("form");
    /**
     * 表单操作
     * @member Ladder.form
     * @class Ladder.form
     */
    Ladder.form={
        /**@cfg*/
        debug:true,
        Components:{
            index:0,
            prefix:'yui',//用于修饰ID
            configs:[
                {id:'eoutHtml',title:'父元素',type:'textarea',index:0,out:0,fetch:'$el.get(0).outerHTML'},
                {id:'fel',title:'父元素',index:1,out:0},
                {id:'cel',title:'子元素',index:2,out:0},
                {id:'mel',title:'当前元素',index:2,out:0},
                {id:'elid',title:'ID',index:3,out:1},
                {id:'elname',title:'元素名称',index:4,out:1},
                {id:'charsize',title:'字段长度',index:6,out:1},
                {id:'cmwidth',title:'宽度',index:5,out:1},
                {id:'cmheight',title:'高度',index:6,out:1},
                {id:'valid',title:'验证约束',index:6,out:1,type:'select',
                    list: "0:无|required:必填项|chinese:输入汉字|number:输入整数|decimal:输入数值|mobile:输入手机号码|email:输入邮箱|cardid:输入身份证",
                    value:'0'},
                {id:'bind',title:'字段绑定',out:1},
                {id:'datatype',title:'字段绑定',out:1},
                {id:'elstyle',title:'元素样式表',type:'textarea',index:100,out:1},
                {id:'elclass',title:'样式类',index:5,out:1}
            ],
            fetchMark:'js-yui',//用户获取元素的标志
            joinRegEx:"(radio)|(checkbox)",//需要对表单合并处理的，此处为正则过滤，比如radio，checkbox，option datalist等
            bulidel:function(el,wname,rw){
                if(!el)return null;
                if(!(el instanceof jQuery)){el=$(el);}
                if(rw==undefined)rw=1;
                rw=((rw)?1:0);
                el.attr("id",this.prefix+(++Ladder.form.Components.index));
                el.attr("data-out",1);
                el.attr('data-wname',wname);
                el.attr("data-rw",rw);
                el.attr("data-bind","");
                el.addClass(this.fetchMark);
                return el;
            },
            label:{
                wname:'label',
                wtitle:'文字标签',
                inithtml:function(){return Ladder.form.Components.bulidel('<label></label>',this.wname,0);}
            },
            linetext:{
                wname:'linetext',
                wtitle:'文本框',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="text">',this.wname);},
                settings:[{id:'cmval',title:'默认值'}]
            },
            combox:{
                wname:'combox',
                wtitle:'下拉选框',
                inithtml:function(){return Ladder.form.Components.bulidel('<select>',this.wname);},
                settings:[
                    {id:'cmval',title:'默认值'},
                    {id:'list',title:'列表项'},
                    {id:'datasource',title:'数据源接口',value:''},
                    {id:'config',title:'数据字典项',button:{title:'获得配置',action:'{webroot}/htmlpage/FormDataConfig.html?type=ddconfigs',name:'ddconfigs'}}
                ]
            },
            datebox:{
                wname:'datebox',
                wtitle:'日期框',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="text" class="databox-icon">',this.wname);},
                settings:[{id:'cmval',title:'默认值'}]
            },
            textfield:{
                wname:'textfield',
                wtitle:'多行文本',
                inithtml:function(){return Ladder.form.Components.bulidel('<textarea></textarea>',this.wname);},
                settings:[{id:'cmval',title:'默认值'}]
            },
            button:{
                wname:'button',
                wtitle:'提交按钮',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="button"  style="width: 30px;height: 26px;">',this.wname,0);},
                settings:[{id:'action',title:'执行动作',type:'select',list:'0:提交表单|1:返回上页',value:'0'}
                    ,{id:'cmval',title:'标题'}]
            },
            restbtn:{
                wname:'restbtn',
                wtitle:'重置按钮',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="button" value="重置">',this.wname,0);},
                settings:[{id:'cmval',title:'标题'}]
            },
            image:{
                wname:'image',
                wtitle:'图片框',
                inithtml:function(){return Ladder.form.Components.bulidel('<img src="" style="height:100px;width: 100px">',this.wname,0);},
                settings:[{id:'elsrc',title:'图片路径'}]
            },
            radio:{
                wname:'radio',
                wtitle:'单选框',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="radio" name="Y'+Ladder.random(4,'string')+Ladder.random(4)+'F">',this.wname,1);},
                settings:[{id:'cmval',title:'选项值'}]
            },
            checkbox:{
                wname:'checkbox',
                wtitle:'复选框',
                inithtml:function(){return Ladder.form.Components.bulidel('<input type="checkbox" name="Y'+Ladder.random(4,'string')+Ladder.random(4)+'F">',this.wname,1);},
                settings:[{id:'cmval',title:'选项值'}]
            },
            imageupload:{
                wname:"imageupload",
                wtitle:'图片上传组件',
                inithtml:function(){
                    return Ladder.form.Components.bulidel('<img class="uploadwidget">',this.wname,1);
                    // return $upload;
                },
                settings:[
                    {id:'autoupload',title:'自动上传',type:'select',list:'1:自动|0:手动',value:'0'},
                    {id:'limitsize',title:'限制大小(KB)',value:1000},
                    {id:'suffix',title:'限制格式',value:"gif,jpg,jpeg,bmp,png"}
                ]
            },
            fileupload:{
                wname:"fileupload",
                wtitle:'附件上传组件',
                inithtml:function(){
                    var $upload= Ladder.form.Components.bulidel('<input type="file" style="border: 1px solid #ccc">',this.wname);
                    //alert("building:"+$upload[0].outerHTML);
                    return $upload;
                },
                settings:[{id:'path',title:'默认文件'}]
            },
            iniframe:{
                wname:'iniframe',
                wtitle:'引用页面',
                inithtml:function(){
                    var $upload= Ladder.form.Components.bulidel('<iframe>',this.wname,0);
                    return $upload;
                },
                settings:[{id:'elframeborder',title:'边框显示',type:'select',list:'1:显示|0:不显示'}
                    ,{id:'elscrolling',title:'是否滚动',type:'select',list:'yes:显示|no:不显示|auto:自动'}
                    ,{id:'elsrc',title:'源地址'}
                ]
            },
            //统一设置相类似元素
            togetherattr:function(el,ename,eval,scope,selector){
                if(!el)return;
                var $el=$(el);
                var pel=null;
                if(!scope) pel= $el.parent();
                else pel =$(el).parents(scope);
                if(pel.length<1)return;
                if(!selector)selector=$el.data("wname")?"[data-wname='"+$el.data("wname")+"']":'';
                if(!selector)selector=$el.prop("tagName");
                var childs = pel.find(selector);
                if(childs.length<1)return;
                for(var i=0;i<childs.length;i++){
                    var $this=$(childs[i]);
                    $this.attr(ename,eval);
                }
            },
            createEl:function(wname){
                if(Ladder.form.Components[wname]){
                    return  Ladder.form.Components[wname].inithtml();
                }else{
                    return Ladder.form.Components.linetext.inithtml();
                }
            }
        },
        /**
         * 验证器
         */
        Valids:{
            //空值
            isNull:function(str){
                if (str == undefined) return true;
                if (("" + str).length < 1)return true;
                var regu = "^[ ]+$";
                var re = new RegExp(regu);
                return re.test(str);
            },
            //isInteger:function( str ) {return /^[-]{0,1}[0-9]{1,}$/.test(str);},
            //正整数
            isInteger:function( str ) {return /^\-?[0-9]{1,}$/.test(str);},
            //手机号码
            isMobile:function( s ) { return (/^[1][3,4,5,7,8][0-9]{9}$/.test(s.replace(/\s*/g,""))); },
            //电子邮箱
            isEMail:function(s) { return /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(s); },
            //isCardID:function(s) { return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(s); },
            //中文
            isChinese: function (s) { return /^[\u4e00-\u9fa5]*$/.test(s); },
            //英文
            isEnglish:function(s){ return /^[a-zA-Z]+$/.test(s);},
            //双精度小数
            isDecimal: function (s) { return /^-?[0-9]+([.]{1}[0-9]+){0,1}$/.test(s); },
            //日期
            isDate:function (s) { return /^(\d{4})\-(\d{2})\-(\d{2})$/.test(s); },
            //日期时间类型
            isDateTime: function (s) { return /^(\d{4})\-(\d{2})\-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/.test(s); },
            //验证身份证
            isIDCard:function(idnumber){
                if(!idnumber||idnumber.length<0)return "身份证必须填写";
                if(idnumber.length==15)return "15位身份证已经不符合国家政策";
                if(idnumber.length!=18)return "身份证必须18位";
                idnumber=idnumber.toUpperCase();
                if(!/^\d{17}([\dx])$/i.test(idnumber))return "身份证数字位不符合规则";
                var address="11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
                var twostr=idnumber.substr(0,2);
                if(address.indexOf(twostr)<0)return "身份证地址错误";
                var year=idnumber.substr(6,4);
                if (year <= 1900 || year >= (new Date()).getFullYear())return "身份证号码中年份不对";
                var m=idnumber.substr(10,2)*1;
                if (m < 1 || m>12)return "身份证号码中月份不对";
                var d=idnumber.substr(12,2)*1;
                if (d< 1 ||d>31)return "身份证号码中日期不对";
                var arrVarifyCode="1,0,X,9,8,7,6,5,4,3,2".split(",");
                var Wi="7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2".split(",");
                var sum=0;
                for(var i=0;i<17;i++){
                    var num=idnumber.substr(i,1)*1;
                    sum+=(Wi[i]*1)*num;
                }
                var n=sum%11;
                if(arrVarifyCode[n]!=idnumber.substr(17,1))return "身份证不为真实证件";
                return "";
            },
            isTel:function(s){return /^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(s);},
            isPhone: function (s) { return (/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/.test(s)) || (/^[1][3,4,5,7,8][0-9]{9}$/.test(s.replace(/\s*/g, ""))); },
            isBankCard: function (s) { var v = parseInt(s);  return /^\d{16}|\d{19}$/.test(v);},
            /**
             * 验证检查
             * @param {} el
             * @returns {}
             */
            check: function (el) {
                var $el = $(el);
                if ($el.is(":hidden")) return true;
                var type=$el.data("datatype")||$el.data("type");
                var length=$el.data("length");
                var valid = $el.data("valid") || $el.data("validate") || $el.attr("validate") || $el.data("elvalidate");
                var reg=$el.attr("data-reg")||$el.data("reg");
                var value = $el.val();
                var hint=$el.data("validhint");
                var selector=$el.data("validselector");
                var isnull=Ladder.form.Valids.isNull(value);
                function tips(message,el){
                    if(selector){
                        var $selector=$(selector);
                        if($selector.length<1)layer.tips(message, el);
                        else{
                            if($selector.attr("data-rawtext")===undefined)$selector.attr("data-rawtext",$selector.text());
                            $selector.html(message);
                            el.off("blur.valid").on("blur.valid", function() {
                                $selector.text($selector.attr("data-rawtext"));
                            });
                        }
                    }else{
                        layer.tips(message, el);
                    }
                }
                //有验证器
                if (valid){
                    if(/(null)|(required)/.test(valid)&&isnull) {
                        tips(hint?hint:"这是必填项", $el);
                        return false;
                    }
                    if (/(mobile)/.test(valid)&&!isnull&&!Ladder.form.Valids.isMobile(value)) {
                        tips(hint?hint:"请填写正确手机号码", $el);
                        return false;
                    }
                    if (/(email)/.test(valid)&&!isnull&&!Ladder.form.Valids.isEMail(value)) {
                        tips(hint?hint:"请填写正确E-Mail地址", $el);
                        return false;
                    }
                    if (/(cardid)|(idcard)/.test(valid)&&!isnull){
                        var re_t= Ladder.form.Valids.isIDCard(value);
                        if(re_t.length>0){
                            layer.tips(re_t, $el);
                            return false;
                        }
                    }
                    //电话号码
                    if(/tel/.test(valid)&&!isnull&&!Ladder.form.Valids.isTel(value)){
                        tips(hint?hint:"请填写正确电话号码", $el);
                        return false;
                    }
                    //联系方式
                    if(/phone/.test(valid)&&!isnull&&!Ladder.form.Valids.isPhone(value)){
                        tips(hint?hint:"请填写正确联系方式", $el);
                        return false;
                    }
                    //if (valid == "cardid") { if (!Ladder.form.Valids.isCardID(value)) return false; }
                    if (/(number)/.test(valid)&&!isnull&&!Ladder.form.Valids.isInteger(value)){
                        tips(hint?hint:"请填写正确的数字格式", $el);
                        return false;
                    }
                    if (/(decimal)/.test(valid)&&!isnull&&!Ladder.form.Valids.isDecimal(value)){
                        tips("请填写正确的数字格式", $el);
                        return false;
                    }
                    if (/(chinese)/.test(valid)&&!isnull&&!Ladder.form.Valids.isChinese(value)){
                        tips(hint?hint:"请填写中文汉字", $el);
                        return false;
                    }
                    if (/(nochn)/.test(valid) && !isnull && Ladder.form.Valids.isChinese(value)) {
                        tips(hint ? hint : "不能包含中文汉字", $el);
                        return false;
                    }
                    if (/(chnpy)/.test(valid) && !isnull && !Ladder.form.Valids.isChinese(value) && !Ladder.form.Valids.isEnglish(value)) {
                        tips(hint ? hint : "请填写中文或拼音", $el);
                        return false;
                    }
                    if (/(bankcard)/.test(valid) && !isnull && !Ladder.form.Valids.isBankCard(value)) {
                        tips(hint ? hint : "请填写正确的银行卡号", $el);
                        return false;
                    }
                    if (/(date)/.test(valid)&&!isnull&&!Ladder.form.Valids.isDate(value)){
                        tips(hint?hint:"请填写正确的时间格式", $el);
                        return false;
                    }
                    if(/eq\([\w\|]*?\)/.test(valid)){
                        if(isnull){
                            tips(hint?hint:"这是必填项", $el);
                            return false;
                        }
                        var match=valid.match(/eq\(([\w\|]*?)\)/);
                        if(match&&match[1]!=undefined){
                            var split=match[1].split("|");
                            var eq=false;
                            for(var i=0;i<split.length;i++){
                                if(split[i]==value){
                                    eq=true;
                                    break;
                                }
                            }
                            if(!eq){
                                tips(hint?hint:"填写值不符合数据标准", $el);
                                return false;
                            }
                        }
                    }
                    //带选择器的大等于验证
                    if(/((eq)|(gte?)|(lte?))\(\s*[#\.]\w*\)/.test(valid)){
                        var validText=valid.match(/((eq)|(gte?)|(lte?))\(\s*[#\.]\w*\)/)[0];
                        var index=validText.indexOf("(");
                        var prefix=validText.substr(0,index);
                        var match=validText.substr(index).match(/\(\s*([#\.]\w*)\)/);
                        if(match&&match[1]){
                            var $diff=$(match[1]);
                            if($diff.length>0&&$diff.val()){
                                if(/eq/.test(prefix)&&$diff.val()!=value){
                                    tips(hint?hint:"填写值必须等于"+$diff.val(), $el);
                                    return false;
                                }
                                if (prefix==="gte" && ((/^\s*\d*\.?\d*\s*$/.test($diff.val())&&/^\s*\d*\.?\d*\s*$/.test(value) && $diff.val() * 1 > value * 1) || (!/^\s*\d*\.?\s*$/.test($diff.val())&& !/^\s*\d*\.?\s*$/.test(value) && $diff.val() > value))) {
                                    tips(hint?hint:"填写值必须大于或等于"+$diff.val(), $el);
                                    return false;
                                }
                                if (prefix==="gt" && ((/^\s*\d*\.?\d*\s*$/.test($diff.val())&&/^\s*\d*\.?\d*\s*$/.test(value) && $diff.val() * 1 >= value * 1) || (!/^\s*\d*\.?\s*$/.test($diff.val())&& !/^\s*\d*\.?\s*$/.test(value) && $diff.val() >= value))) {
                                    tips(hint?hint:"填写值必须大于"+$diff.val(), $el);
                                    return false;
                                }
                                if (prefix==="lte" && ((/^\s*\d*\.?\d*\s*$/.test($diff.val())&&/^\s*\d*\.?\d*\s*$/.test(value) && $diff.val() * 1 < value * 1) || (!/^\s*\d*\.?\s*$/.test($diff.val())&& !/^\s*\d*\.?\s*$/.test(value) && $diff.val() < value))) {
                                    tips(hint?hint:"填写值必须小于或等于"+$diff.val(), $el);
                                    return false;
                                }
                                if (prefix==="lt" && ((/^\s*\d*\.?\d*\s*$/.test($diff.val())&&/^\s*\d*\.?\d*\s*$/.test(value) && $diff.val() * 1 <= value * 1) || (!/^\s*\d*\.?\s*$/.test($diff.val())&& !/^\s*\d*\.?\s*$/.test(value) && $diff.val() <= value))) {
                                    tips(hint?hint:"填写值必须小于"+$diff.val(), $el);
                                    return false;
                                }
                                //if (/lt/.test(prefix) && ((/^\s*\d*\s*$/.test($diff.val() + value) && $diff.val() * 1 < value * 1) || (!/^\s*\d*\s*$/.test($diff.val() + value) && $diff.val() < value))) {
                                //    tips(hint?hint:"填写值必须小于或等于"+$diff.val(), $el);
                                //    return false;
                                //}
                            }
                        }
                    }
                    if(/gte?\(-?\d*\.?\d*\)/.test(valid)){
                        if(isnull){
                            tips(hint?hint:"这是必填项", $el);
                            return false;
                        }
                        if(!Ladder.form.Valids.isDecimal(value)){
                            tips(hint?hint:"请填写正确的数值格式", $el);
                            return false;
                        }
                        var match=valid.match(/(gte?)\((-?\d*\.?\d*)\)/);
                        if(match&&match[2]!=undefined){
                            if(match[1]=="gte"){
                                if(value*1< match[2]*1){
                                    tips(hint?hint:"填写值必须大于"+match[2], $el);
                                    return false;
                                }
                            }else{
                                if(value*1<= match[2]*1){
                                    tips(hint?hint:"填写值必须大于"+match[2], $el);
                                    return false;
                                }
                            }
                        }
                    }
                    if(/lte?\(-?\d*\.?\d*\)/.test(valid)){
                        if(isnull){
                            tips(hint?hint:"这是必填项", $el);
                            return false;
                        }
                        if(!Ladder.form.Valids.isDecimal(value)){
                            tips(hint?hint:"请填写正确的数值格式", $el);
                            return false;
                        }
                        var match=valid.match(/(lte?)\((-?\d*\.?\d*)\)/);
                        if(match&&match[2]!=undefined){
                            if(match[1]=="lte"){
                                if(value*1> match[2]*1){
                                    tips(hint?hint:"填写值必须小于或等于"+match[2], $el);
                                    return false;
                                }
                            }else{
                                if(value*1>= match[2]*1){
                                    tips(hint?hint:"填写值必须小于"+match[2], $el);
                                    return false;
                                }
                            }
                        }
                    }
                    if(/not\([\w\-\.]*\)/.test(valid)){
                        var match=valid.match(/not\(([\w\-\.]*)\)/);
                        if(match&&match[1]!=undefined){
                            if(value == match[1]){
                                tips(hint?hint:"填写值不能等于"+match[1], $el);
                                return false;
                            }
                        }
                    }
                    if(/len(\d+)(-\d*)?/.test(valid)){
                        if(isnull){
                            tips(hint?hint:"值不能为空", $el);
                            return false;
                        }
                        var match = valid.match(/len(\d+)(-(\d*))?/);
                        if(match[1]*1>value.length){
                            tips(hint?hint:"填写内容的长度不能小于"+match[1], $el);
                            return false;
                        }
                        if(match[3]&&match[3]*1<value.length){
                            tips(hint?hint:"填写内容的长度不能大于"+match[3], $el);
                            return false;
                        }
                    }
                }
                if(reg){
                    var regex=new RegExp(reg.replace(/^\//,"").replace(/\/$/,""));
                    if(!regex.test(value)){
                        tips(hint?hint:"填写内容不符合规则", $el);
                        return false;
                    }
                }
                if (type) {
                    if (/(int)|(integer)|(number)|(long)/ig.test(type)) {
                        if (value == undefined) return false;
                        if (!Ladder.form.Valids.isInteger(value)) {
                            tips(hint?hint:"不符合数学规则", $el);
                            return false;
                        }
                        if (value.length > 8) {
                            tips(hint?hint:"不符合数学规则", $el);
                            return false;
                        }
                        return true;
                    }
                    if (/(string)|(char)/ig.test(type)) {
                        if (length != undefined && length > 0) {
                            if (!isnull&& value.length > length) {
                                tips(hint?hint:"字符长度过长", $el);
                                return false;
                            }
                        }
                        return true;
                    }
                    if (/(date$)/ig.test(type)) {
                        if (isnull) return true;
                        if (!Ladder.form.Valids.isDate(value)) {
                            tips(hint?hint:"日期格式不符合规则", $el);
                            return false;
                        }

                        else return true;
                    }
                    if (/(datatime)/gi.test(type)) {
                        if (isnull) return true;
                        if (!Ladder.form.Valids.isDateTime(value)) {
                            tips(hint?hint:"日期时间格式不符合规则", $el);
                            return false;
                        }
                        else return false;
                    }
                }
                if (value != undefined && length > 0) {
                    if (value.toString().length > length) {
                        tips(hint?hint:"内容过长", $el);
                        return false;
                    }
                }
                return true;
            }
        },

        validForm:Ladder.Form.validForm,
        setFormValue:Ladder.Form.setFormValue,
        fetchFormValue:Ladder.Form.fetchFormValue,
        /**
         * 处理表单元素方法，获取和设置.el为表单元素,name为属性值,value为值，如果value==underfind时返回获取值
         * @param {} el
         * @param {} name
         * @param {} value
         * @returns {}
         */
        handleEl:function(el,name,value){
            if((!el) || (!name))return;
            var $el=$(el);
            if($el.length<1)return;
            var stype=name.substr(0,2);
            var changeopt=name.substr(2,name.length-2);
            if(value&&Ladder.getType(value)=='String')value=value.replace(/(^\s)|(\s$)/g,"");
            if(/^(el)|(cm)|(sl)/.test(name)){
                if(stype=='el'){
                    if(value==undefined){
                        if(changeopt=='style')return $el.attr('style')?($el.attr('style')+" ").replace(/\s/g,"").replace(";",';\r'):'';
                        return $el.attr(changeopt);
                    }
                    $el.attr(changeopt,value);
                    //if(changeopt=="name"){
                    //    var re=new RegExp(Ladder.form.Components.joinRegEx,"gi");
                    //    if(re.test($el.data("wname"))){
                    //        var $td=$el.parents("td");
                    //        if($td.length>0){
                    //            var someel=$td.find("[data-wname='"+$el.data("wname")+"']");
                    //            for(var i=0;i<someel.length;i++){
                    //                var thisel=$(someel[i]);
                    //                thisel.attr(changeopt,value);
                    //            }
                    //        }
                    //    }
                    //}
                }
                else if(stype=='sl'){
                    if(value==undefined)return $el.css(changeopt);
                    if(/^width|height/gi.test(changeopt)){
                        eval("$el."+changeopt+"("+(""+value).replace('px','')+")");
                    }else{
                        $el.css(changeopt,value);
                    }
                }
                else if(stype=='cm'){
                    if(value==undefined)return eval("$el."+changeopt+"()");
                    switch (changeopt){
                        case "val":
                            if(Ladder.getType(value)=="Object")$el.val(JSON.stringify(value));
                            else $el.val(value);
                            break;
                        case "css":$el.css(value);break;
                        default :eval("$el."+changeopt+"('"+value+"')");
                    }
                }
                if(/(elname)/gi.test(name)){
                    var re=new RegExp(Ladder.form.Components.joinRegEx,"gi");
                    if(re.test($el.data("wname"))){
                        Ladder.form.Components.togetherattr($el,"name",value,"td");
                    }
                }
            }else{
                //非jqeury属性和自定义属性
                //get属性
                if(value==undefined){
                    return $el.attr("data-"+name);
                }
                if(name=="value"){
                    $el.attr("value",value);
                    $el.removeAttr("data-value");
                    // $el.attr("data-value",value);
                    $el.val(value);
                    return;
                }
                //set属性
                if(name=="list"){
                    if(value.length>0){
                        $el.empty();
                        var items=value.split("|");
                        for(var i=0;i<items.length;i++){
                            var item=items[i].split(":",2);
                            $el.append("<option value='"+item[item.length-1]+"'>"+item[0]+"</option>")
                        }
                    }
                }
                if(name=="datasource"){
                    if($el.data("list"))return;
                    if(/%7B/.test(value))value=decodeURIComponent(value);
                    if(/^\s*\{[\w\W]*?}\s*$/.test(value)||Ladder.getType(value)=="Object"){
                        value = Ladder.toJSON(value);
                        if (value.tableName && !value.url) value.url = URLS.GetData;
                    }else{
                        value={url:value};
                    }
                    if(value.url){

                        var cval=JSON.stringify(value);
                        var newvalue = cval.replace(/(([^@])|^)@[\w-]*\b/,function(old){
                            var first=old.substr(0,1);
                            if(first==="@")first="";
                            var pname=old.replace("@","");
                            return first+($el[0].hasAttribute(pname) ? $el.attr(pname) :undefined);
                        });
                        webajax(Ladder.Service.parseUrl(value.url),Ladder.toJSON(newvalue),function(jsondata){
                            var result=/\.js\?\w*=?/ig.exec(value.url);
                            if(result&&result.length>0){
                                var jnode= result[0];
                                jnode=jnode.replace('.js?','').replace('=','');
                                var jsondata=Ladder.toJSON(jsondata,true);
                                var items=jsondata[jnode];
                                $el.empty();
                                Ladder.form.setSelectValue($el,items,value.keyvalue,value.isClear,value.isUpdateItem);
                            }else{
                                Ladder.form.setSelectValue($el,jsondata,value.keyvalue,value.isClear,value.isUpdateItem);
                            }
                        });
                    }
                }
                if(name=="config"){
                    if($el.data("list"))return;
                    if($el.data("datasource"))return;
                    if(!Ladder.form.Valids.isNull(value)){
                        if(!/\{(.*):(.*)\}$/.test(value)){
                            value=value.replace("{",'').replace("}",'');
                            var sn=value.split("@@");
                            var param=new Object();
                            if(sn.length>1){
                                param.sort=sn[0];
                                param.name=sn[1];
                            }else{
                                param.name=sn[0];
                            }
                            webajax(URLS.URL_Config,param,function(result){
                                if(result.statusCode==200){
                                    var ddata=result.data;
                                    if(!ddata || ddata.length<1)return;
                                    var oldval = $el.val() || $el.data("cmval");
                                    $el.empty();
//                                    $el.append("<option value=''></option>");
                                    for(var i=0;i<ddata.length;i++){
                                        var item=ddata[i];
                                        var _obj=new Object();
                                        if(item.type=="文本型"){//2015-6-25修复
                                            $el.append("<option value='"+item.cvalue+"'>"+item.cvalue+"</option>")
                                            continue;
                                        }
                                        if(item.type=="文本数值型"){
                                            $el.append("<option value='"+item.ivalue+"'>"+item.cvalue+"</option>")
                                            continue;
                                        }
                                        if(item.type=="整数型"){
                                            $el.append("<option value='"+item.ivalue+"'>"+item.ivalue+"</option>")
                                            continue;
                                        }
                                    }
                                    if (oldval) Ladder.form.setSelectValue($el, oldval, false, false);
                                }
                            });
                        }else{
                            var dd= JSON.parse(value);
                            console.log(dd);
                        }
                    }
                }
                if(name=="readonly"){
                    if(!value)$el.prop("readonly",false);
                    else $el.prop("readonly",true);
                }
                if(name=="disabled"){
                    if(!value)$el.prop("disabled",false);
                    else $el.prop("disabled",true);
                }
                if(name=="validate"){
                }
                if(/(bind)|(datatype)|(charsize)|(valid)/gi.test(name)){
                    var re=new RegExp(Ladder.form.Components.joinRegEx,"gi");
                    if(re.test($el.data("wname"))){
                        Ladder.form.Components.togetherattr($el,"data-"+name,value,"td");
                    }
                }
            }
            //非data属性保存
            if(Ladder.getType(value)!="Function")$el.attr("data-"+name,value);
        },
        /**
         * 根据json数据渲染到指定元素中
         * @param {} render
         * @param {} data
         * @param {} callback
         * @returns {}
         */
        buildform:function(render,data,callback){
            var def={tag:'input',type:'text',colspan:1};
            var $table=$(render);
            $table.html("");
            var formjson={
                dataType:'json',
                renderType:'table'
            };
            //data=Ladder.toJSON(data);
            data=JSON.parse(data);
            if(data.forms==undefined && Ladder._is(data,"Array")){
                formjson.forms=data;
            }else{
                formjson=$.extend(formjson,Ladder.toJSON(data));
            }
            if(!formjson.forms)return;
            var Components=Ladder.form.Components;
            for(var x=0;x<formjson.forms.length;x++){
                var $tr=$('<tr></tr>');
                if(formjson.forms[x].length>0){
                    $table.append($tr);
                    for(var y=0 ; y<formjson.forms[x].length;y++){
                        var celldata=formjson.forms[x][y];
                        var $td=$("<td></td>");
                        $td.attr("rowspan",celldata.rowspan);
                        $td.attr("colspan",celldata.colspan);
                        celldata.tdwidth && $td.width(celldata.tdwidth);
                        celldata.tdheight && $td.height(celldata.tdheight);
                        celldata.tdalign && $td.attr("align",celldata.tdalign);
                        if(celldata.html){
                            $td.html(celldata.html);
                        }
                        var wname=celldata.wname;
                        if(wname){
                            var $tel=Components[wname].inithtml();
                            $td.append($tel);
                            var options=Components.configs.concat(Components[wname].settings);
                            for(var i=0;i<options.length;i++){
                                var pname=options[i].id;
                                if(celldata[pname]){
                                    Ladder.form.handleEl($tel,pname,celldata[pname]);
                                }
                            }

                        }
                        $tr.append($td);
                    }
                }
            }
            this.parseEl($table);
            //外部组件333
            if(callback)callback();
            //删除表格空白列
            var trnum=$table.find("tr").length;
            var tdnum=$table.find("tr:first").find("td").length;
            //从左向右删
            for(var d=0;d<tdnum;d++){
                var isdelete=true;
                for(var r=0;r<trnum;r++){
                    var $td=$table.find("tr:eq("+r+") td:eq("+d+")");
                    var html=$td.html();
                    if((html!=undefined&&html.length>1)||$td.attr("colspan")>1){
                        isdelete=false;
                        break;
                    }
                }
                if(isdelete){
                    $table.find("tr td:nth-child("+(d+1)+")").hide();
                }
                else{
                    break;
                }
            }
            //从右向左删
            for(var d=tdnum;d>0;d--){
                var isdelete=true;
                for(var r=trnum;r>0;r--){
                    var $td=$table.find("tr:eq("+r+") td:eq("+d+")");
                    var html=$td.html();
                    if((html!=undefined&&html.length>1)||$td.attr("colspan")>1){
                        isdelete=false;
                        break;
                    }
                }
                if(isdelete){
                    $table.find("tr td:nth-child("+(d+1)+")").hide();
                }
                else{
                    break;
                }
            }
            return $table;
        },
        /**
         * 释放渲染form元素上的设置，普通页面使用本方法更快设置
         * 请求页面配置使用当次请求
         * @param parent
         */
        parseSettings: function (parent) {
            var cfels = $(parent).find("." + this.Components.fetchMark + "[data-config]");
            if (cfels.length > 0) {
                var requestsettings = {};
                for (var i = 0; i < cfels.length; i++) {
                    var $cel = $(cfels[i]);
                    var confs = $cel.data("config");
                    if (Ladder.form.Valids.isNull(confs)) continue;
                    confs = confs.replace(/\{|\}/g, "");

                    var confarray = confs.split("@@");
                    var cname = confarray[0];
                    var ctype = confarray[1];
                    var tname = confarray[2] ? confarray[2] : "dd";
                    $cel.attr("data-crel", "yuicfg" + i);
                    requestsettings["yuicfg" + i] = {
                        rel: "yuicfg" + i,
                        tableName: tname,
                        condition: { name: cname, type: ctype },
                        option: 11
                    };
                }
                webajax(URLS.URL_Query,{ settings: requestsettings }, function(result) {
                    if (result.statusCode != 200) return;
                    for (var key in result.data) {
                        if (result.data[key].statusCode != 200) continue;
                        var ddata = result.data[key].data;
                        if (!ddata || ddata.length < 1) continue;
                        var $cel = $("[data-config][data-crel='" + result.data[key].rel + "']");
                        if ($cel.length < 1) continue;
                        var oldval = $cel.val() || $cel.data("cmval");
                        $cel.empty();
                        for (var i = 0; i < ddata.length; i++) {
                            var item = ddata[i];
                            if(result.data[key].dataName=="dd"){
                                if (item.type == "文本型") {//2015-6-25修复
                                    $cel.append("<option value='" + item.cvalue + "'>" + item.cvalue + "</option>")
                                    continue;
                                }
                                if (item.type == "文本数值型") {
                                    $cel.append("<option value='" + item.ivalue + "'>" + item.cvalue + "</option>")
                                    continue;
                                }
                                if (item.type == "整数型") {
                                    $cel.append("<option value='" + item.ivalue + "'>" + item.ivalue + "</option>")
                                    continue;
                                }
                            }
                        }
                        Ladder.form.setSelectValue($cel, oldval, false, false);
                    }
                });
            }
        },


        /**
         * 渲染form元素,释放form的元素属性
         * @param {} parent
         * @returns {}
         */
        renderForm:function(parent){
            if($(parent).find("."+Ladder.form.Components.fetchMark+"[data-rw=1]").length<1)return true;
            var forms=$(parent).find("."+Ladder.form.Components.fetchMark+"[data-rw=1]");
            for(var m=0;m<forms.length;m++){
                var $tel=$(forms[m]);
                var wname=$tel.data("wname");
                if(wname && Ladder.form.Components.hasOwnProperty(wname)){
                    var options=Ladder.form.Components.configs.concat(Ladder.form.Components[wname].settings);
                    for(var i=0;i<options.length;i++){
                        var pname=options[i].id;
                        if($tel.data(pname)) Ladder.form.handleEl($tel,pname,$tel.data(pname));
                    }
                }
            }
            return true;
        },
        /**
         * 解析form组件,组装form对象到具体的功能
         * @param {} parent 父级容器
         * @param {} isself 是否是自己本身
         * @returns {}
         */
        parseEl:function(parent,isself){
            var thisClass=this;
            if(!parent)return;
            var $parent=$(parent);
            if(isself){
                var wname = $parent.attr("data-wname");
                switch (wname.toLowerCase()){
                    case "datebox":
                        var _type=$parent.attr("data-type")||$parent.attr("data-datatype");
                        if (_type == "datetime") {//需要加载具体时间
                            $parent.attr("onclick", "laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})");
                        }else if(_type == "month"){
                            $parent.attr("onclick", "laydate({istime: true, format: 'YYYY-MM'})");
                        }
                        else {
                            $parent.attr("onclick", "laydate()");
                        }
                        break;
                    case "radio":
                        var title = $parent.attr("data-title") || $parent.attr("data-cmval") || $parent.val();
                        var $next = $parent.next();
                        if ($next.length > 0 && ($next.get(0).tagName.toLowerCase == "span")) return;
                        var $span = $("<span class='radioText'>" + title + "</span>");
                        $parent.after($span);
                }
                return;
            }


            $parent.find(".js-yui[data-wname=\"datebox\"]").each(function () {
                var me=$(this);
                var _type=me.attr("data-type")||me.attr("data-datatype");
                if (_type == "datetime") {//需要加载具体时间
                    me.attr("onclick", "laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})");
                }else if(_type == "month"){
                    me.attr("onclick", "laydate({istime: true, format: 'YYYY-MM'})");
                }
                else {
                    me.attr("onclick", "laydate()");
                }
            });
            $parent.find(".js-yui[data-datasource]").each(function () {
                var me=$(this);
                if(me.attr("data-list")){return;}
                if(!me.attr("data-datasource")){return;}
                me.one("click",function(){
                    me.empty();
                    Ladder.form.handleEl(me,"datasource",me.attr('data-datasource'));
                });
            });
            $parent.find(".js-yui[type='radio']").each(function () {
                var $this = $(this);
                var title = $this.attr("data-title") || $this.attr("data-cmval") || $this.val();
                var $next = $this.next();
                if ($next.length > 0 && ($next.get(0).tagName.toLowerCase == "span")) return;
                var $span = $("<span class='radioText'>" + title + "</span>");
                $this.after($span);
            });
            $parent.find(".js-yui[data-wname=\"button\"]").each(function () {
                var me=$(this);
                me.addClass("btn-default-b");
                me.click(function() {
                    if (Ladder.form.debug)return;
                    var formdata = {
                        tablename:{id:$parent.data("sourceID"),type:"magic"} ,
                        option:$parent.data("option"),
                        condition:$parent.data("condition"),
                        bean:thisClass.fetchFormValue(parent)
                    };
                    webajax(URLS.URL_MagicSave,formdata,function(result){
                        if(result.statusCode==200){
                            layer.msg("恭喜您,保存操作成功");
                        }else{
                            layer.msg(result.message,{icon:2});
                        }
                    });
                });
            });
            if(Ladder.form.debug)return;
            this.parseObject(parent);
        },

        /**
         * 表单验证器，由于笔误单词，且项目已投入使用，需继续保留
         * @param {} parent 父组件
         * @param {} single 是否单件返回
         * @returns {} 全部通过返回真
         */
        vaildForm: function (parent, single) {
            var re_t=true;
//            if($(parent).find("."+Ladder.form.Components.fetchMark+"[data-rw=1]").length<1)return true;
//            var forms=$(parent).find("."+Ladder.form.Components.fetchMark+"[data-rw=1]");
            if ($(parent).find(":input").length < 1) return true;
            var forms = $(parent).find(":input");
            for(var i=0;i<forms.length;i++){
                var me=$(forms[i]);
                if(!Ladder.form.Valids.check(me)){
                    //var oldbackground=me.css("background-color");
                    //var oldborder=me.css("border");

                    me.css("background-color","yellow");
                    me.css("border","1px solid #f00");
                    me.addClass("js-vailderror");
                    //tips(me);
                    //function tips(me){
                    //    layer.tips("数据有效性不符合规则",me);
                    //}
                    me.one("focusout",function() {
                        $(this).css({
                            "background-color": "#FFF",
                            "border": "1px solid #ccc"
                        }).removeClass("js-vailderror");
                    });
                    me.focus();
                    re_t=false;
                    if (single || single === undefined) return re_t;
                }
            }
            return re_t;
        },

        /**
         *解析对象型组件，页面只是标签，对原标签进行重新组装
         *
         */
        parseObject:function(parent){
            if(!parent)return;
            var dd=$(parent);
            $(parent).find(".uploadwidget").each(function(){
                var me=$(this);
                var id=me.attr("id");
                var hideformel=$('<input type="hidden">');
                hideformel.attr("id",id);
                hideformel.addClass(Ladder.form.Components.fetchMark);
                hideformel.attr("data-rw",me.data("rw"));
                hideformel.attr("data-bind",me.data("bind"));
                hideformel.attr("data-wname", "imageupload");
                id = (id ? id : me.data("wname")) + Ladder.random(5);
                hideformel.attr("data-imgrandom", id);
                var index=id.lastIndexOf(".");
                if(index>0)id=id.substring(index+1);
                if(me.data("wname")=='imageupload'){
                    var autoupload=me.data("autoupload")?1:0;
                    var limitsize=me.data("limitsize");
                    var suffix=me.data("suffix");
                    var newel=$('<div style="text-align: center;margin:0 auto;">');
                    newel.width(me.width()==0?150:me.width());newel.height(me.height()==0?150:me.height());
                    var imageview=$('<div style="height:100%;width: 100%;border: 1px solid #ccc;text-align: center">');
                    var picker=$(' <span style="margin-top:2px;padding: 2px 2px;height: 24px;width: 89px;float: left" class="webuploader-pick">选择图片</span>');
                    var btn=$('<button style="height: 28px;width: 50px;/*float: right;*/margin-top: 2px;">上传</button>');
                    picker.attr("id","picker"+id);
                    btn.attr("id","upbtn"+id);
                    imageview.attr("id","imageview"+id);
                    if(me.attr("src")){
                        imageview.html($("<img>").attr("src", me.attr("src")).css({
                            width:"100%",height:"100%"
                        }));
                    }
                    newel.append(imageview);
                    newel.append(picker);
                    newel.append(btn);
                    newel.append(hideformel);
                    me.replaceWith(newel);
                    //me.replaceWith(newel);
                    var uploader = new WebUploader.Uploader({
                        fileVal:'fileData',
                        // swf文件路径
                        swf: Ladder.BasicURL+'/lib/ueditor/third-party/webuploader/YFUploader.swf',
                        // 文件接收服务端。
                        server:Ladder.Service.parseUrl(URLS.URL_CommUpload),
                        // 选择文件的按钮。可选。
                        // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                        pick: '#'+"picker"+id,
                        method:'POST',
                        // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                        resize: false,
                        formData:{action:2222},
                        accept:{
                            title: 'Images',
                            extensions: suffix,
                            mimeTypes: 'image/*'
                        },
                        fileSizeLimit:limitsize*1024,
                        auto:autoupload
                    });
                    uploader.on( 'fileQueued', function( file ) {
                        console.log(file);
                        uploader.makeThumb( file, function( error, src ) {
                            if ( error ) {return;}
                            imageview.html($('<img>').attr( 'src', src ).css({width:"100%",height:"100%"}));
                        });
                    });
                    uploader.on('uploadError', function(file) {
                        alert("error");
                    });
                    uploader.on("uploadSuccess",function(file,response ){
                        var result=Ladder.toJSON(response);
                        if(result.statusCode==200){
                            hideformel.val(result.data);
                        }else{
                            alert("图片未正确上传");
                        }
                    });
                    btn.data("testobj",uploader);
                    btn.click(function(){
                        var files= uploader.getFiles();
                        console.log(files);
                        if(files.length>0){
                            var filename=files[0].name;
                            var formData={
                                argjson:{
                                    usetype:'imageupload',
                                    upuser:'xiaoxiao',
                                    storgemedia:'local',
                                    resid:0,
                                    filename:filename
                                }
                            }
                            formData.argjson=JSON.stringify(formData.argjson);
                            uploader.option("formData",formData);
                            uploader.upload();
                        }
                    })
                    if(autoupload){
                        btn.remove();
                    }
                    hideformel.data("uploader",uploader);
                }
            });
        },
        /**
         * 安装过程
         * @param {} data
         * @param {} fn
         * @returns {}
         */
        wizard:function(data,fn){
            this.$el=null;
            this.init = function(stepArray, fun) {
                var $ul = $("<ul class='wizard'></ul>");
                for (var i = 0; i < stepArray.length; i++) {
                    var $li = $('<li></li>');
                    $li.attr("class", "wizard_step_" + i);
                    $li.attr("data-index", i);
                    var $span = $('<span class="info"></span>');
                    $span.append("<h1>Step " + i + "</h1>");
                    $span.append("<h4>" + stepArray[i] + "</h4>");
                    $li.append($span);
                    $li.append('<span class="icon pass"></span>');
                    $li.click(function() {
                        if (fun)fun($(this).data("index"));
                    });
                    $ul.append($li);
                }
                return $ul;
            };
            this.setcurrent=function(index,wizardel){
                var $ul;
                if(wizardel){
                    $ul=$(wizardel);
                }else{
                    $ul=this.$el;
                }
                var currentel= $ul.find(".wizard_step_"+index).find(".icon");
                if(currentel.length>0){
                    currentel.removeClass("pass");
                    currentel.addClass("current");
                }
            };
            this.getcurrent=function(wizardel){
                var $ul;
                if(wizardel){
                    $ul=$(wizardel);
                }else{
                    $ul=this.$el;
                }
                var $li=$ul.find(".current").parents("li");
                return  $li.attr("class");
            };
            this.getel = function() {
                console.log(this.$el);
                return this.$el;
            };
            if(data){
                this.$el = this.init(data,fn);
            }
            return this;
        },
        /**
         *参阅Ladder.Form.setFormAttr
         */
        setFormAttr: Ladder.Form.setFormAttr,
        /**
         * 参阅Ladder.Form.setSelectValue
         */
        setSelectValue:Ladder.Form.setSelectValue,
        /**
         * 获取绑定的值
         * @param {} bindName
         * @param {} propName
         * @returns {}
         */
        getBindValue:function(bindName,propName){
            var bindel = $("[data-bind='" + bindName + "']");
            if(bindel.length<1)return;
            if(propName){
                if(propName=="val")return bindel.val();
                return bindel.attr(propName);
            }
            return bindel.val()||bindel.attr("value")||bindel.attr("data-value")||bindel.data("value");
        },
        /**
         * 设置元素的绑定的字段值
         * 也用户获取字段元素
         * @param {String} 字段名称
         * @param {Object} 具体的值
         * @param {Boolean} 是否立即呈现 默认是立即呈现 即数据更新在$el.val()方法中
         * @returns {$} 如果成功返回当前元素,失败返回false
         */
        setBindValue: function (bindname, val, appear) {
            var bindel = $("[data-bind='" + bindname + "']");
            if (bindel.length < 1) return false;
            if (val!=undefined) {
                if (bindel[0].tagName == "SELECT") {
                    Ladder.form.setSelectValue(bindel, val);
                    return bindel;
                }
                var _type=Ladder.getType(val);
                if(/(Object)|(Array)/.test(_type)){
                    val=JSON.stringify(val);
                    bindel.attr("data-cmval",val);
                    bindel.attr("data-value",val);
                }else{
                    bindel.attr("data-cmval", val);
                    bindel.attr("data-value", val);
                }
                if (appear == undefined || appear) {
                    bindel.val(val);
                }
            }
            return bindel;
        },
        containValue: function ($el, value) {
            if (!value) return false;
            $el = $($el);
            var _size = $el.find("option[value='" + value + "']").length;
            if (_size > 0)
                return true;
            return false;
        },
        /**
         * 检查元素的权限
         * @param {} $el
         * @returns {}
         */
        checkPermission:function($el) {
            $el = $($el);
            if ($el.attr("data-limit")*1==1) {
                return true;
            } else {
                layer.msg("您没有操作此项功能的权限", { icon: 2 });
                return false;
            }
        },
        /**
         * 检查页面附有权限的元素
         * @param {} page
         * @returns {}
         */
        checkLimit: function (fun) {
            var actionel=$("[data-action]");
            var obj=new Object();
            for(var i=0;i<actionel.length;i++){
                var $this=$(actionel[i]);
                var markName=$this.attr("data-action");
                if(!obj.hasOwnProperty(markName)){
                    obj[markName]=$this;
                    var param = {
                        //cmenuid: cmenuid ? cmenuid : "",
                        name: $this.attr("data-action"),
                        title: $this.attr("data-actionTitle")||$this.attr("data-title")||$this.text(),
                        rel: markName,
                        url:$this.attr("data-page")||window.pageinfo||window.location.href
                    };
                    webajax(URLS.FetchLimit, param, function (json){
                        if (json.statusCode == 200) {
                            obj[json.rel]=json.data * 1;
                            $("[data-action='" + json.rel + "']").each(function() {
                                var me = $(this);
                                me.attr("data-limit", json.data);
                                if (json.data * 1 == 0) {
                                    var eventName = me.attr("data-actionevent")||me.attr("data-event");
                                    if (eventName) {
                                        me.attr("on"+eventName.substring(0,1).toUpperCase()+eventName.substring(1),"");
                                        me.off(eventName);
                                        me.on(eventName, function() {
                                            layer.msg("您没有操作此项功能的权限", { icon: 2 });
                                            return false;
                                        });
                                    } else {
                                        me.off();
                                        me.attr("onClick","");
                                        me.on("click", function() {
                                            layer.msg("您没有操作此项功能的权限", { icon: 2 });
                                            return false;
                                        });
                                    }
                                } else {
                                    //me.css("visibility","visible");
                                    //me.show();
                                }
                                if (fun != undefined && Ladder.getType(fun) == "Function")fun(json.rel, json.data * 1);
                            });
                        }
                    });
                }
            }
        }
    };
    return Ladder;
};
	
	if(typeof define === "function" && define.amd){
		require.config({
		    shim:{
		        // 'webupload':['core'],
		        'layer':['core','laydate']
		    },
		    paths: {
		        'core':'ladder-core',
		         // 'webupload': '../third/webuploader/webuploader.min',
		        'layer':'../third/layer/layer',
                'laydate':"../third/laydate/laydate.dev"
		    }
		});
		define(['layer'],__functionForForm);
	}else{
		__functionForForm();
	}
})();










